home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Extra 1996 #3 / AmigaPlus_CD-ROM-EXTRA_Nr.3.bin / aminet-spiele / role on / larn / object.c < prev    next >
C/C++ Source or Header  |  1997-12-31  |  33KB  |  1,324 lines

  1. /* object.c */
  2. #include "header.h"
  3. #include "larndefs.h"
  4. #include "monsters.h"
  5. #include "objects.h"
  6. #include "player.h"
  7.  
  8. #define min(x,y) (((x)>(y))?(y):(x))
  9. #define max(x,y) (((x)>(y))?(x):(y))
  10.  
  11. /* LOOK_FOR_OBJECT
  12.  subroutine to look for an object and give the player his options if an object
  13.  was found.
  14. */
  15. lookforobject(do_ident, do_pickup, do_action)
  16.     char            do_ident;   /* identify item: T/F */
  17.     char            do_pickup;  /* pickup item:   T/F */
  18.     char            do_action;  /* prompt for actions on object: T/F */
  19. {
  20.     register int    i, j;
  21.  
  22.     /* can't find objects if time is stopped    */
  23.     if (c[TIMESTOP])
  24.         return;
  25.     i = item[playerx][playery];
  26.     if (i == 0)
  27.         return;
  28.     j = iarg[playerx][playery];
  29.     showcell(playerx, playery);
  30.     cursors();
  31.     yrepcount = 0;
  32.     switch (i)
  33.     {
  34.     case OGOLDPILE:
  35.     case OMAXGOLD:
  36.     case OKGOLD:
  37.     case ODGOLD:
  38.         lprcat("\n\nYou have found some gold!");
  39.         ogold(i);
  40.         break;
  41.  
  42.     case OPOTION:
  43.         if (do_ident)
  44.         {
  45.             lprcat("\n\nYou have found a magic potion");
  46.             if (potionname[j][0])
  47.                 lprintf(" of %s", &potionname[j][1]);
  48.         }
  49.         if (do_pickup)
  50.             if (take(OPOTION, j) == 0)
  51.                 forget();
  52.         if (do_action)
  53.             opotion(j);
  54.         break;
  55.  
  56.     case OSCROLL:
  57.         if (do_ident)
  58.         {
  59.             lprcat("\n\nYou have found a magic scroll");
  60.             if (scrollname[j][0])
  61.                 lprintf(" of %s", &scrollname[j][1]);
  62.         }
  63.         if (do_pickup)
  64.             if (take(OSCROLL, j) == 0)
  65.                 forget();
  66.         if (do_action)
  67.             oscroll(j);
  68.         break;
  69.  
  70.     case OALTAR:
  71.         if (nearbymonst())
  72.             return;
  73.         if (do_ident)
  74.             lprcat("\n\nThere is a Holy Altar here!");
  75.         if (do_action)
  76.             oaltar();
  77.         break;
  78.  
  79.     case OBOOK:
  80.         if (do_ident)
  81.             lprcat("\n\nYou have found a book.");
  82.         if (do_pickup)
  83.             if (take(OBOOK, j) == 0)
  84.                 forget();
  85.         if (do_action)
  86.             obook();
  87.         break;
  88.  
  89.     case OCOOKIE:
  90.         if (do_ident)
  91.             lprcat("\n\nYou have found a fortune cookie.");
  92.         if (do_pickup)
  93.             if (take(OCOOKIE, 0) == 0)
  94.                 forget();
  95.         if (do_action)
  96.             ocookie();
  97.         break;
  98.  
  99.     case OTHRONE:
  100.         if (nearbymonst())
  101.             return;
  102.         if (do_ident)
  103.             lprintf("\n\nThere is %s here!", objectname[i]);
  104.         if (do_action)
  105.             othrone(0);
  106.         break;
  107.  
  108.     case OTHRONE2:
  109.         if (nearbymonst())
  110.             return;
  111.         if (do_ident)
  112.             lprintf("\n\nThere is %s here!", objectname[i]);
  113.         if (do_action)
  114.             othrone(1);
  115.         break;
  116.  
  117.     case ODEADTHRONE:
  118.         if (do_ident)
  119.             lprintf("\n\nThere is %s here!", objectname[i]);
  120.         if (do_action)
  121.             odeadthrone();
  122.         break;
  123.  
  124.     case OPIT:
  125.         /* always perform these actions. */
  126.         lprcat("\n\nYou're standing at the top of a pit.");
  127.         opit();
  128.         break;
  129.  
  130.     case OSTAIRSUP: /* up */
  131.         if (do_ident)
  132.             lprcat("\n\nThere is a circular staircase here");
  133.         if (do_action)
  134.             ostairs(1);
  135.         break;
  136.  
  137.     case OFOUNTAIN:
  138.         if (nearbymonst())
  139.             return;
  140.         if (do_ident)
  141.             lprcat("\n\nThere is a fountain here");
  142.         if (do_action)
  143.             ofountain();
  144.         break;
  145.  
  146.     case OSTATUE:
  147.         if (nearbymonst())
  148.             return;
  149.         if (do_ident)
  150.             lprcat("\n\nYou are standing in front of a statue");
  151.         if (do_action)
  152.             ostatue();
  153.         break;
  154.  
  155.     case OCHEST:
  156.         if (do_ident)
  157.             lprcat("\n\nThere is a chest here");
  158.         if (do_pickup)
  159.             if (take(OCHEST, j) == 0)
  160.                 forget();
  161.         if (do_action)
  162.             ochest();
  163.         break;
  164.  
  165.     case OSCHOOL:
  166.         if (nearbymonst())
  167.             return;
  168.         if (do_ident)
  169.             lprcat("\n\nYou have found the College of Larn.");
  170.         if (do_action)
  171.             prompt_enter();
  172.         break;
  173.  
  174.     case OMIRROR:
  175.         if (nearbymonst())
  176.             return;
  177.         if (do_ident)
  178.             lprcat("\n\nThere is a mirror here");
  179.         if (do_action)
  180.             omirror();
  181.         break;
  182.  
  183.     case OBANK2:
  184.         if (nearbymonst())
  185.             return;
  186.         if (do_ident)
  187.             lprcat("\n\nYou have found a branch office of the bank of Larn.");
  188.         if (do_action)
  189.             prompt_enter();
  190.         break;
  191.  
  192.     case OBANK:
  193.         if (nearbymonst())
  194.             return;
  195.         if (do_ident)
  196.             lprcat("\n\nYou have found the bank of Larn.");
  197.         if (do_action)
  198.             prompt_enter();
  199.         break;
  200.  
  201.     case ODEADFOUNTAIN:
  202.         if (nearbymonst())
  203.             return;
  204.         if (do_ident)
  205.             lprcat("\n\nThere is a dead fountain here");
  206.         break;
  207.  
  208.     case ODNDSTORE:
  209.         if (nearbymonst())
  210.             return;
  211.         if (do_ident)
  212.             lprcat("\n\nThere is a DND store here.");
  213.         if (do_action)
  214.             prompt_enter();
  215.         break;
  216.  
  217.     case OSTAIRSDOWN:   /* down */
  218.         if (do_ident)
  219.             lprcat("\n\nThere is a circular staircase here");
  220.         if (do_action)
  221.             ostairs(-1);
  222.         break;
  223.  
  224.     case OOPENDOOR:
  225.         if (do_ident)
  226.             lprintf("\n\nYou have found %s", objectname[i]);
  227.         if (do_action)
  228.             o_open_door();
  229.         break;
  230.  
  231.     case OCLOSEDDOOR:
  232.         if (do_ident)
  233.             lprintf("\n\nYou have found %s", objectname[i]);
  234.         if (do_action)
  235.             o_closed_door();
  236.         break;
  237.  
  238.     case OENTRANCE:
  239.         if (do_ident)
  240.             lprcat("\nYou have found ");
  241.         lprcat(objectname[i]);
  242.         if (do_action)
  243.             prompt_enter();
  244.         break;
  245.  
  246.     case OVOLDOWN:
  247.         if (do_ident)
  248.             lprcat("\nYou have found ");
  249.         lprcat(objectname[i]);
  250.         if (do_action)
  251.             prompt_volshaft(-1);
  252.         break;
  253.  
  254.     case OVOLUP:
  255.         if (do_ident)
  256.             lprcat("\nYou have found ");
  257.         lprcat(objectname[i]);
  258.         if (do_action)
  259.             prompt_volshaft(1);
  260.         break;
  261.  
  262.     case OIVTELETRAP:
  263.         if (rnd(11) < 6)
  264.             return;
  265.         item[playerx][playery] = OTELEPORTER;
  266.         know[playerx][playery] = KNOWALL;
  267.         /* fall through to OTELEPORTER case below!!! */
  268.  
  269.     case OTELEPORTER:
  270.         lprcat("\nZaaaappp!  You've been teleported!\n");
  271.         beep();
  272.         nap(3000);
  273.         oteleport(0);
  274.         break;
  275.  
  276.     case OTRAPARROWIV:  /* for an arrow trap */
  277.         if (rnd(17) < 13)
  278.             return;
  279.         item[playerx][playery] = OTRAPARROW;
  280.         know[playerx][playery] = 0;
  281.         /* fall through to OTRAPARROW case below!!! */
  282.  
  283.     case OTRAPARROW:
  284.         lprcat("\nYou are hit by an arrow");
  285.         beep();
  286.         lastnum = 259;
  287.         losehp(rnd(10) + level);
  288.         bottomhp();
  289.         return;
  290.  
  291.     case OIVDARTRAP:    /* for a dart trap */
  292.         if (rnd(17) < 13)
  293.             return;
  294.         item[playerx][playery] = ODARTRAP;
  295.         know[playerx][playery] = 0;
  296.         /* fall through to ODARTTRAP case below!!! */
  297.  
  298.     case ODARTRAP:
  299.         lprcat("\nYou are hit by a dart");
  300.         beep();     /* for a dart trap */
  301.         lastnum = 260;
  302.         losehp(rnd(5));
  303.         if ((--c[STRENGTH]) < 3)
  304.             c[STRENGTH] = 3;
  305.         bottomline();
  306.         return;
  307.  
  308.     case OIVTRAPDOOR:   /* for a trap door */
  309.         if (rnd(17) < 13)
  310.             return;
  311.         item[playerx][playery] = OTRAPDOOR;
  312.         know[playerx][playery] = KNOWALL;
  313.         /* fall through to OTRAPDOOR case below!!! */
  314.  
  315.     case OTRAPDOOR:
  316.         lastnum = 272;  /* a trap door */
  317.         if ((level == MAXLEVEL - 1) || (level == MAXLEVEL + MAXVLEVEL - 1))
  318.         {
  319.             lprcat("\nYou fell through a bottomless trap door!");
  320.             beep();
  321.             nap(3000);
  322.             died(271);
  323.         }
  324.         i = rnd(5 + level);
  325.         lprintf("\nYou fall through a trap door!  You lose %d hit points.", (long) i);
  326.         beep();
  327.         losehp(i);
  328.         nap(2000);
  329.         newcavelevel(level + 1);
  330.         draws(0, MAXX, 0, MAXY);
  331.         bot_linex();
  332.         return;
  333.  
  334.     case OTRADEPOST:
  335.         if (nearbymonst())
  336.             return;
  337.         if (do_ident)
  338.             lprcat("\nYou have found the Larn trading Post.");
  339.         if (do_action)
  340.             prompt_enter();
  341.         return;
  342.  
  343.     case OHOME:
  344.         if (nearbymonst())
  345.             return;
  346.         if (do_ident)
  347.             lprcat("\nYou have found your way home.");
  348.         if (do_action)
  349.             prompt_enter();
  350.         return;
  351.  
  352.     case OWALL:
  353.         break;
  354.  
  355.     case OANNIHILATION:
  356.         died(283);  /* annihilated by sphere of annihilation */
  357.         return;
  358.  
  359.     case OLRS:
  360.         if (nearbymonst())
  361.             return;
  362.         if (do_ident)
  363.             lprcat("\n\nThere is an LRS office here.");
  364.         if (do_action)
  365.             prompt_enter();
  366.         break;
  367.  
  368.     default:
  369.         if (do_ident)
  370.         {
  371.             lprintf("\n\nYou have found %s ", objectname[i]);
  372.             switch (i)
  373.             {
  374.             case ODIAMOND:
  375.             case ORUBY:
  376.             case OEMERALD:
  377.             case OSAPPHIRE:
  378.             case OSPIRITSCARAB:
  379.             case OORBOFDRAGON:
  380.             case OCUBEofUNDEAD:
  381.             case ONOTHEFT:
  382.                 break;
  383.  
  384.             default:
  385.                 if (j > 0)
  386.                     lprintf("+ %d", (long) j);
  387.                 else
  388.                 if (j < 0)
  389.                     lprintf(" %d", (long) j);
  390.                 break;
  391.             }
  392.         }
  393.         if (do_pickup)
  394.             if (take(i, j) == 0)
  395.                 forget();
  396.         if (do_action)
  397.         {
  398.             char            tempc = 0;
  399.  
  400.             lprcat("\nDo you want to (t) take it");
  401.             iopts();
  402.             while (tempc != 't' && tempc != 'i' && tempc != '\33')
  403.                 tempc = ttgetch();
  404.             if (tempc == 't')
  405.             {
  406.                 lprcat("take");
  407.                 if (take(i, j) == 0)
  408.                     forget();
  409.                 return;
  410.             }
  411.             ignore();
  412.         }
  413.         break;
  414.     };
  415. }
  416.  
  417.  
  418. /*
  419.  * subroutine to process the stair cases if dir > 0 the up else down 
  420.  */
  421. static ostairs(dir)
  422.     int             dir;
  423. {
  424.     register int    k;
  425.     lprcat("\nDo you (s) stay here ");
  426.     if (dir > 0)
  427.         lprcat("or (u) go up? ");
  428.     else
  429.         lprcat("or (d) go down? ");
  430.  
  431.     while (1)
  432.         switch (ttgetch())
  433.         {
  434.         case '\33':
  435.         case 's':
  436.         case 'i':
  437.             lprcat("stay here");
  438.             return;
  439.  
  440.         case 'u':
  441.             lprcat("go up");
  442.             act_up_stairs();
  443.             return;
  444.  
  445.         case 'd':
  446.             lprcat("go down");
  447.             act_down_stairs();
  448.             return;
  449.         };
  450. }
  451.  
  452.  
  453.  
  454. /*
  455.  * subroutine to handle a teleport trap +/- 1 level maximum 
  456.  */
  457. oteleport(err)
  458.     int             err;
  459. {
  460.     register int    tmp;
  461.     if (err)
  462.         if (rnd(151) < 3)
  463.             died(264);  /* stuck in a rock */
  464.     c[TELEFLAG] = 1;    /* show ?? on bottomline if been teleported    */
  465.     if (level == 0)
  466.         tmp = 0;
  467.     else
  468.     if (level < MAXLEVEL)
  469.     {
  470.         tmp = rnd(5) + level - 3;
  471.         if (tmp >= MAXLEVEL)
  472.             tmp = MAXLEVEL - 1;
  473.         if (tmp < 1)
  474.             tmp = 1;
  475.     } else
  476.     {
  477.         tmp = rnd(3) + level - 2;
  478.         if (tmp >= MAXLEVEL + MAXVLEVEL)
  479.             tmp = MAXLEVEL + MAXVLEVEL - 1;
  480.         if (tmp < MAXLEVEL)
  481.             tmp = MAXLEVEL;
  482.     }
  483.     playerx = rnd(MAXX - 2);
  484.     playery = rnd(MAXY - 2);
  485.     if (level != tmp)
  486.         newcavelevel(tmp);
  487.     positionplayer();
  488.     draws(0, MAXX, 0, MAXY);
  489.     bot_linex();
  490. }
  491.  
  492.  
  493. /*
  494.  * function to process a potion 
  495.  */
  496. static opotion(pot)
  497.     int             pot;
  498. {
  499.     lprcat("\nDo you (d) drink it, (t) take it");
  500.     iopts();
  501.     while (1)
  502.         switch (ttgetch())
  503.         {
  504.         case '\33':
  505.         case 'i':
  506.             ignore();
  507.             return;
  508.  
  509.         case 'd':
  510.             lprcat("drink\n");
  511.             forget();   /* destroy potion  */
  512.             quaffpotion(pot, TRUE);
  513.             return;
  514.  
  515.         case 't':
  516.             lprcat("take\n");
  517.             if (take(OPOTION, pot) == 0)
  518.                 forget();
  519.             return;
  520.         };
  521. }
  522.  
  523. /*
  524.  * function to drink a potion 
  525.  *
  526.  * Also used to perform the action of a potion without quaffing a potion (see
  527.  * invisible capability when drinking from a fountain). 
  528.  */
  529. quaffpotion(pot, set_known)
  530.     int             pot;
  531.     int             set_known;
  532. {
  533.     register int    i, j, k;
  534.  
  535.     /* check for within bounds */
  536.     if (pot < 0 || pot >= MAXPOTION)
  537.         return;
  538.  
  539.     /*
  540.      * if player is to know this potion (really quaffing one), make it
  541.      * known 
  542.      */
  543.     if (set_known)
  544.         potionname[pot][0] = ' ';
  545.  
  546.     switch (pot)
  547.     {
  548.     case 0:
  549.         lprcat("\nYou fall asleep. . .");
  550.         i = rnd(11) - (c[CONSTITUTION] >> 2) + 2;
  551.         while (--i > 0)
  552.         {
  553.             parse2();
  554.             nap(1000);
  555.         }
  556.         cursors();
  557.         lprcat("\nYou woke up!");
  558.         return;
  559.  
  560.     case 1:
  561.         lprcat("\nYou feel better");
  562.         if (c[HP] == c[HPMAX])
  563.             raisemhp(1);
  564.         else
  565.         if ((c[HP] += rnd(20) + 20 + c[LEVEL]) > c[HPMAX])
  566.             c[HP] = c[HPMAX];
  567.         break;
  568.  
  569.     case 2:
  570.         lprcat("\nSuddenly, you feel much more skillful!");
  571.         raiselevel();
  572.         raisemhp(1);
  573.         return;
  574.  
  575.     case 3:
  576.         lprcat("\nYou feel strange for a moment");
  577.         c[rund(6)]++;
  578.         break;
  579.  
  580.     case 4:
  581.         lprcat("\nYou feel more self confident!");
  582.         c[WISDOM] += rnd(2);
  583.         break;
  584.  
  585.     case 5:
  586.         lprcat("\nWow!  You feel great!");
  587.         if (c[STRENGTH] < 12)
  588.             c[STRENGTH] = 12;
  589.         else
  590.             c[STRENGTH]++;
  591.         break;
  592.  
  593.     case 6:
  594.         lprcat("\nYour charm went up by one!");
  595.         c[CHARISMA]++;
  596.         break;
  597.  
  598.     case 7:
  599.         lprcat("\nYou become dizzy!");
  600.         if (--c[STRENGTH] < 3)
  601.             c[STRENGTH] = 3;
  602.         break;
  603.  
  604.     case 8:
  605.         lprcat("\nYour intelligence went up by one!");
  606.         c[INTELLIGENCE]++;
  607.         break;
  608.  
  609.     case 9:
  610.         lprcat("\nYou sense the presence of objects!");
  611.         nap(1000);
  612.         if (c[BLINDCOUNT])
  613.             return;
  614.         for (i = 0; i < MAXY; i++)
  615.             for (j = 0; j < MAXX; j++)
  616.                 switch (item[j][i])
  617.                     {
  618.                     case OPLATE:
  619.                     case OCHAIN:
  620.                     case OLEATHER:
  621.                     case ORING:
  622.                     case OSTUDLEATHER:
  623.                     case OSPLINT:
  624.                     case OPLATEARMOR:
  625.                     case OSSPLATE:
  626.                     case OSHIELD:
  627.                     case OSWORDofSLASHING:
  628.                     case OHAMMER:
  629.                     case OSWORD:
  630.                     case O2SWORD:
  631.                     case OSPEAR:
  632.                     case ODAGGER:
  633.                     case OBATTLEAXE:
  634.                     case OLONGSWORD:
  635.                     case OFLAIL:
  636.                     case OLANCE:
  637.                     case ORINGOFEXTRA:
  638.                     case OREGENRING:
  639.                     case OPROTRING:
  640.                     case OENERGYRING:
  641.                     case ODEXRING:
  642.                     case OSTRRING:
  643.                     case OCLEVERRING:
  644.                     case ODAMRING:
  645.                     case OBELT:
  646.                     case OSCROLL:
  647.                     case OPOTION:
  648.                     case OBOOK:
  649.                     case OCHEST:
  650.                     case OAMULET:
  651.                     case OORBOFDRAGON:
  652.                     case OSPIRITSCARAB:
  653.                     case OCUBEofUNDEAD:
  654.                     case ONOTHEFT:
  655.                     case OCOOKIE:
  656.                         know[j][i] = HAVESEEN;
  657.                         show1cell(j, i);
  658.                         break;
  659.                     }
  660.         showplayer();
  661.         return;
  662.  
  663.     case 10:        /* monster detection */
  664.         lprcat("\nYou detect the presence of monsters!");
  665.         nap(1000);
  666.         if (c[BLINDCOUNT])
  667.             return;
  668.         for (i = 0; i < MAXY; i++)
  669.             for (j = 0; j < MAXX; j++)
  670.                 if (mitem[j][i] && (monstnamelist[mitem[j][i]] != floorc))
  671.                 {
  672.                     know[j][i] = HAVESEEN;
  673.                     show1cell(j, i);
  674.                 }
  675.         return;
  676.  
  677.     case 11:
  678.         lprcat("\nYou stagger for a moment . .");
  679.         for (i = 0; i < MAXY; i++)
  680.             for (j = 0; j < MAXX; j++)
  681.                 know[j][i] = 0;
  682.         nap(1000);
  683.         draws(0, MAXX, 0, MAXY);    /* potion of forgetfulness */
  684.         return;
  685.  
  686.     case 12:
  687.         lprcat("\nThis potion has no taste to it");
  688.         return;
  689.  
  690.     case 13:
  691.         lprcat("\nYou can't see anything!");    /* blindness */
  692.         c[BLINDCOUNT] += 500;
  693.         return;
  694.  
  695.     case 14:
  696.         lprcat("\nYou feel confused");
  697.         c[CONFUSE] += 20 + rnd(9);
  698.         return;
  699.  
  700.     case 15:
  701.         lprcat("\nWOW!!!  You feel Super-fantastic!!!");
  702.         if (c[HERO] == 0)
  703.             for (i = 0; i < 6; i++)
  704.                 c[i] += 11;
  705.         c[HERO] += 250;
  706.         break;
  707.  
  708.     case 16:
  709.         lprcat("\nYou have a greater intestinal constitude!");
  710.         c[CONSTITUTION]++;
  711.         break;
  712.  
  713.     case 17:
  714.         lprcat("\nYou now have incredibly bulging muscles!!!");
  715.         if (c[GIANTSTR] == 0)
  716.             c[STREXTRA] += 21;
  717.         c[GIANTSTR] += 700;
  718.         break;
  719.  
  720.     case 18:
  721.         lprcat("\nYou feel a chill run up your spine!");
  722.         c[FIRERESISTANCE] += 1000;
  723.         break;
  724.  
  725.     case 19:
  726.         lprcat("\nYou feel greedy . . .");
  727.         nap(1000);
  728.         if (c[BLINDCOUNT])
  729.             return;
  730.         for (i = 0; i < MAXY; i++)
  731.             for (j = 0; j < MAXX; j++)
  732.             {
  733.                 k = item[j][i];
  734.                 if ((k == ODIAMOND)  ||
  735.                     (k == ORUBY)     ||
  736.                     (k == OEMERALD)  ||
  737.                     (k == OMAXGOLD)  ||
  738.                     (k == OSAPPHIRE) ||
  739.                     (k == OLARNEYE)  ||
  740.                     (k == OGOLDPILE))
  741.                 {
  742.                     know[j][i] = HAVESEEN;
  743.                     show1cell(j, i);
  744.                 }
  745.             }
  746.         showplayer();
  747.         return;
  748.  
  749.     case 20:
  750.         c[HP] = c[HPMAX];
  751.         break;      /* instant healing */
  752.  
  753.     case 21:
  754.         lprcat("\nYou don't seem to be affected");
  755.         return;     /* cure dianthroritis */
  756.  
  757.     case 22:
  758.         lprcat("\nYou feel a sickness engulf you"); /* poison */
  759.         c[HALFDAM] += 200 + rnd(200);
  760.         return;
  761.  
  762.     case 23:
  763.         lprcat("\nYou feel your vision sharpen");   /* see invisible */
  764.         c[SEEINVISIBLE] += rnd(1000) + 400;
  765.         monstnamelist[INVISIBLESTALKER] = 'I';
  766.         return;
  767.     };
  768.     bottomline();       /* show new stats      */
  769.     return;
  770. }
  771.  
  772.  
  773. /*
  774.  * function to process a magic scroll 
  775.  */
  776. static oscroll(typ)
  777.     int             typ;
  778. {
  779.     lprcat("\nDo you ");
  780.     if (c[BLINDCOUNT] == 0)
  781.         lprcat("(r) read it, ");
  782.     lprcat("(t) take it");
  783.     iopts();
  784.     while (1)
  785.         switch (ttgetch())
  786.         {
  787.         case '\33':
  788.         case 'i':
  789.             ignore();
  790.             return;
  791.  
  792.         case 'r':
  793.             if (c[BLINDCOUNT])
  794.                 break;
  795.             lprcat("read");
  796.             forget();
  797.             if (typ == 2 || typ == 15)
  798.             {
  799.                 show1cell(playerx, playery);
  800.                 cursors();
  801.             }
  802.              /* destroy it  */ read_scroll(typ);
  803.             return;
  804.  
  805.         case 't':
  806.             lprcat("take");
  807.             if (take(OSCROLL, typ) == 0)
  808.                 forget();   /* destroy it  */
  809.             return;
  810.         };
  811. }
  812.  
  813. /*
  814.  * data for the function to read a scroll 
  815.  */
  816. static int   xh, yh, yl, xl;
  817. static char  curse[] = {BLINDCOUNT, CONFUSE, AGGRAVATE, HASTEMONST, ITCHING,
  818.                         LAUGHING, DRAINSTRENGTH, CLUMSINESS, INFEEBLEMENT, 
  819.                         HALFDAM};
  820. static char  exten[] = {PROTECTIONTIME, DEXCOUNT, STRCOUNT, CHARMCOUNT,
  821.                         INVISIBILITY, CANCELLATION, HASTESELF, GLOBE,
  822.                         SCAREMONST, HOLDMONST, TIMESTOP};
  823. static char  time_change[] = {HASTESELF, HERO, ALTPRO, PROTECTIONTIME, DEXCOUNT,
  824.                               STRCOUNT, GIANTSTR, CHARMCOUNT, INVISIBILITY,
  825.                               CANCELLATION,HASTESELF, AGGRAVATE, SCAREMONST,
  826.                               STEALTH, AWARENESS, HOLDMONST, HASTEMONST,
  827.                               FIRERESISTANCE, GLOBE, SPIRITPRO, UNDEADPRO,
  828.                               HALFDAM, SEEINVISIBLE, ITCHING, CLUMSINESS, WTW};
  829. /*
  830.  * function to adjust time when time warping and taking courses in school
  831.  */
  832. adjtime(tim)
  833.     register long   tim;
  834. {
  835.     register int    j;
  836.     for (j = 0; j < 26; j++)/* adjust time related parameters */
  837.         if (c[time_change[j]])
  838.             if ((c[time_change[j]] -= tim) < 1)
  839.                 c[time_change[j]] = 1;
  840.     regen();
  841. }
  842.  
  843. /*
  844.  * function to read a scroll 
  845.  */
  846. read_scroll(typ)
  847.     int             typ;
  848. {
  849.     register int    i, j;
  850.     if (typ < 0 || typ >= MAXSCROLL)
  851.         return;     /* be sure we are within bounds */
  852.     scrollname[typ][0] = ' ';
  853.     switch (typ)
  854.     {
  855.     case 0:
  856.         lprcat("\nYour armor glows for a moment");
  857.         enchantarmor();
  858.         return;
  859.  
  860.     case 1:
  861.         lprcat("\nYour weapon glows for a moment");
  862.         enchweapon();
  863.         return;     /* enchant weapon */
  864.  
  865.     case 2:
  866.         lprcat("\nYou have been granted enlightenment!");
  867.         yh = min(playery + 7, MAXY);
  868.         xh = min(playerx + 25, MAXX);
  869.         yl = max(playery - 7, 0);
  870.         xl = max(playerx - 25, 0);
  871.         for (i = yl; i < yh; i++)
  872.             for (j = xl; j < xh; j++)
  873.                 know[j][i] = KNOWALL;
  874.         draws(xl, xh, yl, yh);
  875.         return;
  876.  
  877.     case 3:
  878.         lprcat("\nThis scroll seems to be blank");
  879.         return;
  880.  
  881.     case 4:
  882.         createmonster(makemonst(level + 1));
  883.         return;     /* this one creates a monster  */
  884.  
  885.     case 5:
  886.         something(level);   /* create artifact     */
  887.         return;
  888.  
  889.     case 6:
  890.         c[AGGRAVATE] += 800;
  891.         return;     /* aggravate monsters */
  892.  
  893.     case 7:
  894.         gtime += (i = rnd(1000) - 850); /* time warp */
  895.         if (i >= 0)
  896.             lprintf("\nYou went forward in time by %d mobuls", (long) ((i + 99) / 100));
  897.         else
  898.             lprintf("\nYou went backward in time by %d mobuls", (long) (-(i + 99) / 100));
  899.         adjtime((long) i);  /* adjust time for time warping */
  900.         return;
  901.  
  902.     case 8:
  903.         oteleport(0);
  904.         return;     /* teleportation */
  905.  
  906.     case 9:
  907.         c[AWARENESS] += 1800;
  908.         return;     /* expanded awareness   */
  909.  
  910.     case 10:
  911.         c[HASTEMONST] += rnd(55) + 12;
  912.         return;     /* haste monster */
  913.  
  914.     case 11:
  915.         for (i = 0; i < MAXY; i++)
  916.             for (j = 0; j < MAXX; j++)
  917.                 if (mitem[j][i])
  918.                     hitp[j][i] = monster[mitem[j][i]].hitpoints;
  919.         return;     /* monster healing */
  920.     case 12:
  921.         c[SPIRITPRO] += 300 + rnd(200);
  922.         bottomline();
  923.         return;     /* spirit protection */
  924.  
  925.     case 13:
  926.         c[UNDEADPRO] += 300 + rnd(200);
  927.         bottomline();
  928.         return;     /* undead protection */
  929.  
  930.     case 14:
  931.         c[STEALTH] += 250 + rnd(250);
  932.         bottomline();
  933.         return;     /* stealth */
  934.  
  935.     case 15:
  936.         lprcat("\nYou have been granted enlightenment!");   /* magic mapping */
  937.         for (i = 0; i < MAXY; i++)
  938.             for (j = 0; j < MAXX; j++)
  939.                 know[j][i] = KNOWALL;
  940.         draws(0, MAXX, 0, MAXY);
  941.         return;
  942.  
  943.     case 16:
  944.         c[HOLDMONST] += 30;
  945.         bottomline();
  946.         return;     /* hold monster */
  947.  
  948.     case 17:
  949.         for (i = 0; i < 26; i++)    /* gem perfection */
  950.             switch (iven[i])
  951.             {
  952.             case ODIAMOND:
  953.             case ORUBY:
  954.             case OEMERALD:
  955.             case OSAPPHIRE:
  956.                 j = ivenarg[i];
  957.                 j &= 255;
  958.                 j <<= 1;
  959.                 if (j > 255)
  960.                     j = 255;    /* double value */
  961.                 ivenarg[i] = j;
  962.                 break;
  963.             }
  964.         break;
  965.  
  966.     case 18:
  967.         for (i = 0; i < 11; i++)
  968.             c[exten[i]] <<= 1;  /* spell extension */
  969.         break;
  970.  
  971.     case 19:
  972.         for (i = 0; i < 26; i++)    /* identify */
  973.         {
  974.             if (iven[i] == OPOTION)
  975.                 potionname[ivenarg[i]][0] = ' ';
  976.             if (iven[i] == OSCROLL)
  977.                 scrollname[ivenarg[i]][0] = ' ';
  978.         }
  979.         break;
  980.  
  981.     case 20:
  982.         for (i = 0; i < 10; i++)    /* remove curse */
  983.             if (c[curse[i]])
  984.                 c[curse[i]] = 1;
  985.         break;
  986.  
  987.     case 21:
  988.         annihilate();
  989.         break;      /* scroll of annihilation */
  990.  
  991.     case 22:
  992.         godirect(22, 150, "The ray hits the %s", 0, ' ');   /* pulverization */
  993.         break;
  994.     case 23:
  995.         c[LIFEPROT]++;
  996.         break;      /* life protection */
  997.     };
  998. }
  999.  
  1000. static opit()
  1001. {
  1002.     register int    i;
  1003.     if (rnd(101) < 81)
  1004.         if (rnd(70) > 9 * c[DEXTERITY] - packweight() || rnd(101) < 5)
  1005.             if (level == MAXLEVEL - 1)
  1006.                 obottomless();
  1007.             else
  1008.             if (level == MAXLEVEL + MAXVLEVEL - 1)
  1009.                 obottomless();
  1010.             else
  1011.             {
  1012.                 if (rnd(101) < 20)
  1013.                 {
  1014.                     i = 0;
  1015.                     lprcat("\nYou fell into a pit!  Your fall is cushioned by an unknown force\n");
  1016.                 } else
  1017.                 {
  1018.                     i = rnd(level * 3 + 3);
  1019.                     lprintf("\nYou fell into a pit!  You suffer %d hit points damage", (long) i);
  1020.                     lastnum = 261;  /* if he dies scoreboard
  1021.                              * will say so */
  1022.                 }
  1023.                 losehp(i);
  1024.                 nap(2000);
  1025.                 newcavelevel(level + 1);
  1026.                 draws(0, MAXX, 0, MAXY);
  1027.             }
  1028. }
  1029.  
  1030. static obottomless()
  1031. {
  1032.     lprcat("\nYou fell into a bottomless pit!");
  1033.     beep();
  1034.     nap(3000);
  1035.     died(262);
  1036. }
  1037.  
  1038. static ostatue()
  1039. {
  1040. }
  1041.  
  1042. static omirror()
  1043. {
  1044. }
  1045.  
  1046. static obook()
  1047. {
  1048.     lprcat("\nDo you ");
  1049.     if (c[BLINDCOUNT] == 0)
  1050.         lprcat("(r) read it, ");
  1051.     lprcat("(t) take it");
  1052.     iopts();
  1053.     while (1)
  1054.         switch (ttgetch())
  1055.         {
  1056.         case '\33':
  1057.         case 'i':
  1058.             ignore();
  1059.             return;
  1060.  
  1061.         case 'r':
  1062.             if (c[BLINDCOUNT])
  1063.                 break;
  1064.             lprcat("read");
  1065.              /* no more book */ readbook(iarg[playerx][playery]);
  1066.             forget();
  1067.             return;
  1068.  
  1069.         case 't':
  1070.             lprcat("take");
  1071.             if (take(OBOOK, iarg[playerx][playery]) == 0)
  1072.                 forget();   /* no more book */
  1073.             return;
  1074.         };
  1075. }
  1076.  
  1077. /*
  1078.  * function to read a book 
  1079.  */
  1080. readbook(lev)
  1081.     register int    lev;
  1082. {
  1083.     register int    i, tmp;
  1084.     if (lev <= 3)
  1085.         i = rund((tmp = splev[lev]) ? tmp : 1);
  1086.     else
  1087.         i = rnd((tmp = splev[lev] - 9) ? tmp : 1) + 9;
  1088.     spelknow[i] = 1;
  1089.     lprintf("\nSpell \"%s\":  %s\n%s", spelcode[i], spelname[i], speldescript[i]);
  1090.     if (rnd(10) == 4)
  1091.     {
  1092.         lprcat("\nYour int went up by one!");
  1093.         c[INTELLIGENCE]++;
  1094.         bottomline();
  1095.     }
  1096. }
  1097.  
  1098. static ocookie()
  1099. {
  1100.     char           *p;
  1101.     lprcat("\nDo you (e) eat it, (t) take it");
  1102.     iopts();
  1103.     while (1)
  1104.         switch (ttgetch())
  1105.         {
  1106.         case '\33':
  1107.         case 'i':
  1108.             ignore();
  1109.             return;
  1110.  
  1111.         case 'e':
  1112.             lprcat("eat");
  1113.             forget();   /* no more cookie */
  1114.             outfortune();
  1115.             return;
  1116.  
  1117.         case 't':
  1118.             lprcat("take");
  1119.             if (take(OCOOKIE, 0) == 0)
  1120.                 forget();   /* no more book */
  1121.             return;
  1122.         };
  1123. }
  1124.  
  1125. /*
  1126.  * routine to pick up some gold -- if arg==OMAXGOLD then the pile is worth
  1127.  * 100* the argument
  1128.  */
  1129. static ogold(arg)
  1130.     int             arg;
  1131. {
  1132.     register long   i;
  1133.     i = iarg[playerx][playery];
  1134.     if (arg == OMAXGOLD)
  1135.         i *= 100;
  1136.     else
  1137.     if (arg == OKGOLD)
  1138.         i *= 1000;
  1139.     else
  1140.     if (arg == ODGOLD)
  1141.         i *= 10;
  1142.     lprintf("\nIt is worth %d!", (long) i);
  1143.     c[GOLD] += i;
  1144.     bottomgold();
  1145.     item[playerx][playery] = know[playerx][playery] = 0;    /* destroy gold    */
  1146. }
  1147.  
  1148. ohome()
  1149. {
  1150.     register int    i;
  1151.     nosignal = 1;       /* disable signals */
  1152.     for (i = 0; i < 26; i++)
  1153.         if (iven[i] == OPOTION)
  1154.             if (ivenarg[i] == 21)
  1155.             {
  1156.                 iven[i] = 0;    /* remove the potion of cure
  1157.                          * dianthroritis from
  1158.                          * inventory */
  1159.                 clear();
  1160.                 lprcat("Congratulations.  You found a potion of cure dianthroritis.\n");
  1161.                 lprcat("\nFrankly, No one thought you could do it.  Boy!  Did you surprise them!\n");
  1162.                 if (gtime > TIMELIMIT)
  1163.                 {
  1164.                     lprcat("\nThe doctor has the sad duty to inform you that your daughter died");
  1165.                     lprcat("\nbefore your return.  There was nothing he could do without the potion.\n");
  1166.                     nap(5000);
  1167.                     died(269);
  1168.                 } else
  1169.                 {
  1170.                     lprcat("\nThe doctor is now administering the potion, and in a few moments\n");
  1171.                     lprcat("your daughter should be well on her way to recovery.\n");
  1172.                     nap(6000);
  1173.                     lprcat("\nThe potion is");
  1174.                     nap(3000);
  1175.                     lprcat(" working!  The doctor thinks that\n");
  1176.                     lprcat("your daughter will recover in a few days.  Congratulations!\n");
  1177.                     beep();
  1178.                     nap(5000);
  1179.                     died(263);
  1180.                 }
  1181.             }
  1182.     while (1)
  1183.     {
  1184.         clear();
  1185.         lprintf("Welcome home %s.  Latest word from the doctor is not good.\n", logname);
  1186.  
  1187.         if (gtime > TIMELIMIT)
  1188.         {
  1189.             lprcat("\nThe doctor has the sad duty to inform you that your daughter died!\n");
  1190.             lprcat("You didn't make it in time.  There was nothing he could do without the potion.\n");
  1191.             nap(5000);
  1192.             died(269);
  1193.         }
  1194.         lprcat("\nThe diagnosis is confirmed as dianthroritis.  He guesses that\n");
  1195.         lprintf("your daughter has only %d mobuls left in this world.  It's up to you,\n", (long) ((TIMELIMIT - gtime + 99) / 100));
  1196.         lprintf("%s, to find the only hope for your daughter, the very rare\n", logname);
  1197.         lprcat("potion of cure dianthroritis.  It is rumored that only deep in the\n");
  1198.         lprcat("depths of the caves can this potion be found.\n\n\n");
  1199.         lprcat("\n     ----- press ");
  1200.         standout("return");
  1201.         lprcat(" to continue, ");
  1202.         standout("escape");
  1203.         lprcat(" to leave ----- ");
  1204.         i = ttgetch();
  1205.         while (i != '\33' && i != '\n')
  1206.             i = ttgetch();
  1207.         if (i == '\33')
  1208.         {
  1209.             drawscreen();
  1210.             nosignal = 0;   /* enable signals */
  1211.             return;
  1212.         }
  1213.     }
  1214. }
  1215.  
  1216. /* routine to save program space   */
  1217. iopts()
  1218. {
  1219.     lprcat(", or (i) ignore it? ");
  1220. }
  1221. ignore()
  1222. {
  1223.     lprcat("ignore\n");
  1224. }
  1225.  
  1226. /*
  1227.  * For prompt mode, prompt for entering a building.
  1228.  */
  1229. static prompt_enter()
  1230. {
  1231.     char            i;
  1232.  
  1233.     lprcat("\nDo you (g) go inside, or (i) stay here? ");
  1234.     i = 0;
  1235.     while ((i != 'g') && (i != 'i') && (i != '\33'))
  1236.         i = ttgetch();
  1237.     if (i == 'g')
  1238.         enter();
  1239.     else
  1240.         lprcat(" stay here");
  1241. }
  1242.  
  1243. /*
  1244.  * For prompt mode, prompt for climbing up/down the volcanic shaft. 
  1245.  *
  1246.  * Takes one parameter: if it is negative, going down the shaft, otherwise,
  1247.  * going up the shaft. 
  1248.  */
  1249. static prompt_volshaft(dir)
  1250.     int             dir;
  1251. {
  1252.     char            i;
  1253.  
  1254.     lprcat("\nDo you (c) climb ");
  1255.     if (dir > 0)
  1256.         lprcat("up");
  1257.     else
  1258.         lprcat("down");
  1259.     iopts();
  1260.  
  1261.     i = 0;
  1262.     while ((i != 'c') && (i != 'i') && (i != '\33'))
  1263.         i = ttgetch();
  1264.  
  1265.     if ((i == '\33') || (i == 'i'))
  1266.     {
  1267.         ignore();
  1268.         return;
  1269.     }
  1270.     if (dir > 0)
  1271.         act_up_shaft();
  1272.     else
  1273.         act_down_shaft();
  1274. }
  1275.  
  1276. static o_open_door()
  1277. {
  1278.     char            i;
  1279.     lprcat("\nDo you (c) close it");
  1280.     iopts();
  1281.     i = 0;
  1282.     while ((i != 'c') && (i != 'i') && (i != '\33'))
  1283.         i = ttgetch();
  1284.     if ((i == '\33') || (i == 'i'))
  1285.     {
  1286.         ignore();
  1287.         return;
  1288.     }
  1289.     lprcat("close");
  1290.     forget();
  1291.     item[playerx][playery] = OCLOSEDDOOR;
  1292.     iarg[playerx][playery] = 0;
  1293.     playerx = lastpx;
  1294.     playery = lastpy;
  1295. }
  1296.  
  1297. static o_closed_door()
  1298. {
  1299.     char            i;
  1300.     lprcat("\nDo you (o) try to open it");
  1301.     iopts();
  1302.     i = 0;
  1303.     while ((i != 'o') && (i != 'i') && (i != '\33'))
  1304.         i = ttgetch();
  1305.     if ((i == '\33') || (i == 'i'))
  1306.     {
  1307.         ignore();
  1308.         playerx = lastpx;
  1309.         playery = lastpy;
  1310.         return;
  1311.     } else
  1312.     {
  1313.         lprcat("open");
  1314.         /*
  1315.          * if he failed to open the door ... 
  1316.          */
  1317.         if (!act_open_door(playerx, playery))
  1318.         {
  1319.             playerx = lastpx;
  1320.             playery = lastpy;
  1321.         }
  1322.     }
  1323. }
  1324.